package com.ssl.springframework.beans.factory.support;

import com.ssl.springframework.beans.factory.config.BeanDefinition;

/**
 * 描述：
 *
 * @author ssl
 * @create 2021/6/10 0010.
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory {

    @Override
    protected Object createBean(String name, BeanDefinition beanDefinition) {
        Object bean;
        try {
            // TODO 假如需要实例化的对象 没有无参构造函数，则会报错
            bean = beanDefinition.getBean().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException("Instantiation of bean failed", e);
        }
        // 放入单例bean缓存池
        addSingleton(name, bean);
        return bean;
    }
}
